﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DataFrameworkAccess;
using CommonFramework.Storage.Cache;
using Back.Xinkui.Common.Const;

namespace Back.Xinkui.Common.Control.DataDictionary
{
    public class DataDictionaryManager
    {
        private static List<DataDictionaryeEntity> _DataDictionary;
        private static object lockObj = new object();
        public static List<DataDictionaryeEntity> DataDictionary
        {
            get
            {
                if (_DataDictionary == null)
                {
                    lock (lockObj)
                    {
                        if (_DataDictionary == null)
                        {
                            _DataDictionary = CacheManager.CreateCache(VerifyManageKey.APSOTO_TRADE_DATADICT).Get<List<DataDictionaryeEntity>>(VerifyManageKey.APSOTO_TRADE_DATADICT);
                            if (_DataDictionary == null)
                            {
                                _DataDictionary = GetAllDataDict();
                                CacheManager.CreateCache(VerifyManageKey.APSOTO_TRADE_DATADICT).Set<List<DataDictionaryeEntity>>(VerifyManageKey.APSOTO_TRADE_DATADICT, _DataDictionary);
                            }
                        }
                    }
                }
                return _DataDictionary;
            }
        }


        private static List<DataDictionaryeEntity> GetAllDataDict()
        {
            DataCommand cmd = DataCommandManager.GetDataCommand("DataDict.Query.GetAll");
            return cmd.ExecuteEntityList<DataDictionaryeEntity>();
        }

    }
}
